package com.example.myworkers.controller;

import com.example.myworkers.model.Labor;
import com.example.myworkers.model.Record;
import com.example.myworkers.service.LaborService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 编写者：门硕然
 */

@Api(tags = "Labor")
@RestController
@RequestMapping("/labor")
public class LaborController {

    @Autowired
    private LaborService laborService;

    @ApiOperation(value = "添加方法")
    @PostMapping("/addLabor")
    @CrossOrigin
    public int addLabor(@RequestBody Labor labor){
        System.out.println("进入添加信息接口");
        return laborService.insertLabor(labor);
    }


    @ApiOperation(value = "查询方法-单个")
    @GetMapping("/getOne")
    @CrossOrigin
    public Labor getLabor(int id){
        System.out.println("进入单条查询接口");
        Labor labor=laborService.selectLabor(id);
        System.out.println("返回的数据集合为"+labor.getLabordate());
        return labor;
    }


    @ApiOperation(value = "删除方法")
    @GetMapping("/deleteLabor")
    @CrossOrigin
    public int deleteLabor(int id){
        System.out.println("进入删除接口");
        int returnValue=0;
        if (id!=0){
            returnValue=laborService.deleteLabor(id);
        }
        return returnValue;
    }

    @ApiOperation(value = "修改方法")
    @PostMapping("/editLabor")
    @CrossOrigin
    public int editLabor(@RequestBody Labor labor){
        System.out.println("进入修改接口");
        return laborService.updateLabor(labor);
    }


}
